package com.stars.empoly.activity

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.provider.Settings
import android.text.TextUtils
import android.util.Log
import android.view.KeyEvent
import com.qmuiteam.qmui.kotlin.onClick
import com.stars.empoly.base.MBActivity
import com.stars.empoly.config.MIntentAction
import com.stars.empoly.databinding.ActivityLoginBinding
import com.stars.empoly.vmodel.LoginVModel
import com.trailer.base.ccretrofit.CCRetrofit
import com.trailer.base.route.IUpdate
import com.trailer.base.utils.B
import com.trailer.base.utils.UiSwitch

class LoginActivity : MBActivity<LoginVModel, ActivityLoginBinding>() {


    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)

        vm.code = Settings.System.getString(
                contentResolver, Settings.Secure.ANDROID_ID)


        Log.e("-shy-", "android_id=: " + vm.code)

        //检查更新
//        CCRetrofit.instance()
//                .create(IUpdate::class.java)
//                .checkUpgrade(false)
//                .subscribe()
    }

    override fun listeners() {
        super.listeners()
        binding.llRegist.onClick {

            UiSwitch.bundleRes(this, RegisterActivity::class.java,
                    B().putString("adminType", vm.adminType).ok(), MIntentAction.REQUEST_CODE_ONE)

        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (MIntentAction.REQUEST_CODE_ONE == requestCode && resultCode == Activity.RESULT_OK) {
            val bundle = data!!.extras
            if (null != bundle) {

                var adminType=bundle.getString("adminType")
                if(!TextUtils.isEmpty(adminType)&&adminType.equals("driver")){
                    vm.toChose(2)
                }

            }
        }

    }


    override fun title(): String? {
        return null
    }

    override fun binding(): ActivityLoginBinding {
        return ActivityLoginBinding.inflate(layoutInflater)
    }

    override fun vmClass(): Class<LoginVModel> {
        return LoginVModel::class.java
    }


    override val isRxbus: Boolean
        get() = true


    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode === KeyEvent.KEYCODE_BACK) {
            val home = Intent(Intent.ACTION_MAIN)
            home.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP
            home.addCategory(Intent.CATEGORY_HOME)
            startActivity(home)
            return true
        }
        return super.onKeyDown(keyCode, event)
    }

    /**
     * 双击退出函数
     */
    private var isExit = false



}
